<template>
    <div>
        <div>
            <!--查询表单-->
            <el-form :inline="true" :model="searchFormData" class="demo-form-inline">
                <el-form-item label="套餐名称">
                    <el-select v-model="searchFormData.comboName" placeholder="套餐名称">
                        <el-option v-for="item in combos" :label="item.label"
                                   :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="客户名称">
                    <el-input v-model="searchFormData.userName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="searchSubmit">查询</el-button>
                    <el-button type="success" @click="addClick">新增</el-button>
                </el-form-item>
            </el-form>
        </div>
        <!--表格-->
        <el-table :data="tableData" height="500px" max-height="500px" class="c-no-wrap">
            <el-table-column prop="comboName" label="套餐名称" align="center"/>
            <el-table-column prop="comboSize" label="套餐规格" align="center"/>
            <el-table-column prop="comboType" label="套餐类型" align="center"/>
            <el-table-column prop="salePrice" label="套餐售价" align="center"/>
            <el-table-column prop="customer" label="客户" align="center"/>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button @click="editClick(scope.row)" type="primary" size="mini">编辑</el-button>
                    <el-button :type="type=='danger'? type:'primary'" size="mini" @click="delClick(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--翻页-->
        <div>
            <pageHelper :current-page="currentPage" :total="total" @sizeChange="handleSizeChange"
                        @currentChange="handleCurrentChange" class="my_pagenation"/>
        </div>
        <!--新增表单-->
        <el-dialog title="新增" :visible.sync="addDialogFormVisible" @close="addFormClose"  width="500px">
            <el-form :model="addForm" class="my_el_form">
                <el-form-item label="通道名称" :label-width="formLabelWidth">
                    <el-input v-model="addForm.channelName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="运营商" :label-width="formLabelWidth">
                    <el-input v-model="addForm.vendor" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="用户名" :label-width="formLabelWidth">
                    <el-input v-model="addForm.username" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addDialogFormVisible=false">取 消</el-button>
                <el-button type="primary" @click="addConfirm">确 定</el-button>
            </div>
        </el-dialog>
        <!--编辑表单-->
        <el-dialog title="编辑" :visible.sync="editDialogFormVisible" @close="editFormClose" width="500px">
            <el-form :model="editForm" class="my_el_form">
                <el-form-item label="通道名称" :label-width="formLabelWidth">
                    <el-input v-model="editForm.channelName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="运营商" :label-width="formLabelWidth">
                    <el-input v-model="editForm.vendor" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="用户名" :label-width="formLabelWidth">
                    <el-input v-model="editForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth">
                    <el-input v-model="editForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="key" :label-width="formLabelWidth">
                    <el-input v-model="editForm.key" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="接口地址" :label-width="formLabelWidth">
                    <el-select v-model="editForm.url" placeholder="接口地址">
                        <el-option label="区域一" value="shanghai"></el-option>
                        <el-option label="区域二" value="beijing"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="editDialogFormVisible=false">取 消</el-button>
                <el-button type="primary" @click="editConfirm">确 定</el-button>
            </div>
        </el-dialog>
        <loading v-if="loading"></loading>
    </div>
</template>

<script>
    import axios from 'axios';
    import pageHelper from '@/website/center/common/pageHelper';
    import {mytips} from '@/module/tools';
    import {Loading} from 'element-ui';

    export default {
        name: 'rateList',
        components: {pageHelper, Loading},
        data() {
            return {
                currentPage: 2,
                total: 120,
                type: "danger",
                loading: false,
                loadInstance: null,
                totalPage: 10,
                addDialogFormVisible: false,
                editDialogFormVisible: false,
                formLabelWidth: '80px',
                tableData: [{
                    comboName: '黑皮40G',
                    comboSize: '40G',
                    comboType: '月套餐',
                    salePrice: 300,
                    customer: "王涛",
                }],
                searchFormData: {
                    comboName: '',
                    userName: ''
                },
                combos:
                    [{label: "套餐1", value: 1},
                        {label: "套餐2", value: 2},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3},
                        {label: "套餐3", value: 3}
                    ],
                apiAddress:
                    [
                        {label: "地址1", value: 1},
                        {label: "地址2", value: 2},
                        {label: "地址3", value: 3}],
                addForm:
                    {
                        channelName: '',
                        vendor: '',
                        username: '',
                    }
                ,
                editForm: {
                    channelName: '',
                    vendor: '',
                    username: '',
                    password: '',
                    key: '',
                    url: ''
                },
            };
        },
        methods: {
            /*翻页跳转处理，传入页数*/
            getData: function (page) {
                console.log("======页数==" + page);
            },
            delClick(row) {
                console.log(row);
                console.log('==删除操作==时间' + row.date);
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    setTimeout('console.log("模拟函数调用")', 2000);
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    // window.location.reload();
                }).catch(() => {
                    /*  this.$message({
                          type: 'info',
                          message: '已取消删除'
                      });*/
                    console.log("取消")
                });
            },
            searchSubmit() {
                console.log('查询提交');
                console.log(this.searchFormData);
            },
            addClick() {
                this.addDialogFormVisible = true;
            },
            //确认新增
            addConfirm() {
                console.log("获取新增表的数据");
                console.log(this.addForm);
                this.addDialogFormVisible = false;
            },
            editClick(row) {
                console.log('==编辑操作==');
                console.log(row);
                this.editForm.channelName = row.channel,
                    this.editForm.vendor = row.channel,
                    this.editForm.username = row.channel,
                    this.editForm.password = row.channel,
                    this.editForm.key = row.channel,
                    this.editDialogFormVisible = true;
            },
            //确认修改
            editConfirm(row) {
                //发送请求后再关闭，关闭会清空表单数据
                this.editDialogFormVisible = false;

            },
            editCancel() {
                this.clearEditForm();
                this.editDialogFormVisible = false;
                //注意关闭数据后的数据清楚
            },
            clearEditForm() {
                this.editForm = {
                    channelName: '',
                    vendor: '',
                    username: '',
                    password: '',
                    key: '',
                    url: ''
                }
            },
            //状态的值转换
            getStatusName(tableData) {
                let objs = this.$data.tableData;
                for (let obj in objs) {
                    switch (obj.status) {
                        case 0:
                            obj.status = "可用"
                            break;
                        case 1:
                            obj.status = "不可用"
                            break;
                        default:
                            obj.status = "未知"
                    }
                }
            },
            addFormClose() {
                console.log("新增的对话窗关闭回调");
                //todo 清空新增框的参数
            },
            editFormClose() {
                console.log("编辑的对话窗关闭回调");
                //todo 清空编辑框的参数
            },
            handleSizeChange(val) {
                console.log(`123每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`345当前页: ${val}`);
            }

        },
        filters: {
            handleStatus: function (value) {
                switch (value) {
                    case 0:
                        return "可用";
                        break;
                    case 1:
                        return "不可用";
                        break;
                    default:
                        return "未知";
                }
            }
        },
        mounted() {
            console.log("mount=====");
            console.log(this.$data);
            let obj = {
                comboName: '黑皮40G',
                comboSize: '40G',
                comboType: '月套餐',
                salePrice: 300,
                customer: "王涛",
            };
            let i = 0;
            for (i = 0; i < 5; i++) {
                console.log("添加对象")
                this.$data.tableData.push(obj);
            }
        }

    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
    .express-ctr-item {
        margin-top: 12px;
    }

    .express-ctr-item .express-ctr-label {
        display: inline-block;
        width: 100px;
        text-align: right;
        line-height: 32px;
    }

    .my_el_form input {
        width: 200px;
    }
</style>

